package com.zyzg.repository;

import com.zyzg.domain.GpsData;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Repository
public interface GpsDataRepository extends MongoRepository<GpsData, String> {
    
    Page<GpsData> findByConfigIdAndGpsTimeBetween(
        String configId,
        Date startTime, 
        Date endTime, 
        Pageable pageable
    );

    List<GpsData> findAllByConfigIdAndGpsTimeBetween(
            int configId,
            Long startTime,
            Long endTime
    );

    // 查询最早一条数据（最小时间戳）
    GpsData findFirstByConfigIdAndGpsTimeBetweenOrderByGpsTimeAsc(int configId,Long startTime,Long endTime);

    // 查询最晚一条数据（最大时间戳）
    GpsData findFirstByConfigIdAndGpsTimeBetweenOrderByGpsTimeDesc(
            int configId,
            Long startTime,
            Long endTime
    );
}